#include "ShaderLib.h"

namespace egg{

    ShaderLib gShaderLib;

    ShaderPtr ShaderLib::getShader(const string& name){
        unordered_map<string,ShaderPtr>::iterator itr=mShaders.find(name);
        if(itr!=mShaders.end()){
            return itr->second;
        }else{
            LogMgr->logMessage(name+" shader not exist");
            return ShaderPtr(0);
        }
    }

    ShaderPtr ShaderLib::loadShader(const string& name,const string& vs,const string& fs){
        unordered_map<string,ShaderPtr>::iterator itr=mShaders.find(name);
        if(itr!=mShaders.end()){
            LogMgr->logMessage(name+" shader already exist");
            return itr->second;
        }else{
            ShaderPtr ret(new Shader());
            ret->fromFile(vs,fs);
            mShaders.insert(make_pair(name,ret));
            return ret;
        }
    }

}